package com.wuhuahe.learning.lagou.service.resume.controller;

import com.wuhuahe.learning.lagou.service.resume.pojo.Resume;
import com.wuhuahe.learning.lagou.service.resume.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;


    @Value("${server.port}")
    private Integer port;

    //"/resume/openstate/1545132"
    @GetMapping("/openstate/{userId}")
    public Integer findDefaultResumeState(@PathVariable Long userId) {

        Resume resume = resumeService.findDefaultResumeByUserId(userId);
        if (resume != null) {
            return resume.getIsOpenResume();
        } else {
            return -9999;
        }
    }

    @GetMapping("/openstate2/{userId}")
    public String findDefaultResumeState2(@PathVariable Long userId) {

        Resume resume = resumeService.findDefaultResumeByUserId(userId);
        if (resume != null) {
            return resume.getIsOpenResume() + "，来自于" + port;
        } else {
            return -9999+ "，来自于" + port;
        }
    }


    @GetMapping("/openstate3/{userId}")
    public String findDefaultResumeState3(@PathVariable Long userId) {

        if(port == 8081){
            try {
                Thread.sleep(10000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        Resume resume = resumeService.findDefaultResumeByUserId(userId);
        if (resume != null) {
            return resume.getIsOpenResume() + "，来自于" + port;
        } else {
            return -9999+ "，来自于" + port;
        }
    }
}
